﻿using UnityEngine;
using System.Collections;

public class objGravity : MonoBehaviour {

	public float gravForce = 1.0f;
	public float gravDist = 100.0f;
	
	// Update is called once per frame
	void FixedUpdate () {

		// adding gravity effect to player
		GameObject[] gravObjects = GameObject.FindGameObjectsWithTag("Player");
		foreach (GameObject g in gravObjects) {
			Vector3 direction = transform.position - g.transform.position;
			gravDist = direction.magnitude;
			direction.Normalize();
			g.rigidbody2D.AddForce(direction * (gravForce / gravDist));
		}
		/*
		// adding gravity effect to projectile1
		GameObject[] gravObjects2 = GameObject.FindGameObjectsWithTag("projectile1");
		foreach (GameObject g in gravObjects2) {
			Vector3 direction = transform.position - g.transform.position;
			gravDist = direction.magnitude;
			direction.Normalize();
			g.rigidbody2D.AddForce(direction * (gravForce / gravDist));
		}
		*/
	}
}
